package com.ihome.android.util;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.URL;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern;

import org.apache.http.NameValuePair;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageManager;
import android.content.res.AssetManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Environment;
import android.os.StatFs;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;

import com.ihome.android.common.ComParams;
import com.ihome.android.academy.R;
import com.ihome.android.util.exception.ITVException;
import com.ihome.android.util.log.LogUtil;

/**
 * Utility class
 * 
 * @author Emerson
 * 
 */
public class Util {
	private static final String	TAG		= Util.class.getSimpleName();
	private static final int	ERROR	= -1;

	public static void gotoWifiSettings(Context context) throws Exception {

		try {
			Intent intent5 = new Intent();
			intent5.setClassName("com.android.settings", "com.android.settings.wifi.WifiSettings");
			intent5.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			context.startActivity(intent5);
		} catch (Exception e) {
			e.printStackTrace();
			try {
				Intent intent = new Intent(Settings.ACTION_WIRELESS_SETTINGS);
				intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				context.startActivity(intent);
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		}

	}

	/**
	 * 判断是否有网络
	 */
	public static boolean isNetworkAvailable(Context context) {
		ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
		return (networkInfo != null && networkInfo.isAvailable());

	}

	/**
	 * 获取网络接入方式
	 */
	public static String getNetworkType(Context context) {
		ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
		return (networkInfo != null ? networkInfo.getTypeName() : "没有网络连接，请检查您的网络！");
	}

	/** 转换dip为px **/
	public static int convertDIP2PX(Context context, int dip) {
		float scale = context.getResources().getDisplayMetrics().density;
		return (int) (dip * scale + 0.5f * (dip >= 0 ? 1 : -1));
	}

	/** 转换px为dip **/
	public static int convertPX2DIP(Context context, int px) {
		float scale = context.getResources().getDisplayMetrics().density;
		return (int) (px / scale + 0.5f * (px >= 0 ? 1 : -1));
	}

	/**
	 * SDCARD是否存
	 */
	public static boolean externalMemoryAvailable() {
		return android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
	}

	/**
	 * 获取手机内部剩余存储空间
	 * 
	 * @return
	 */
	public static long getAvailableInternalMemorySize() {
		File path = Environment.getDataDirectory();
		StatFs stat = new StatFs(path.getPath());
		long blockSize = stat.getBlockSize();
		long availableBlocks = stat.getAvailableBlocks();
		return availableBlocks * blockSize;
	}

	/**
	 * 获取手机内部总的存储空间
	 * 
	 * @return
	 */
	public static long getTotalInternalMemorySize() {
		File path = Environment.getDataDirectory();
		StatFs stat = new StatFs(path.getPath());
		long blockSize = stat.getBlockSize();
		long totalBlocks = stat.getBlockCount();
		return totalBlocks * blockSize;
	}

	/**
	 * 获取SDCARD剩余存储空间
	 * 
	 * @return
	 */
	public static long getAvailableExternalMemorySize() {
		if (externalMemoryAvailable()) {
			File path = Environment.getExternalStorageDirectory();
			StatFs stat = new StatFs(path.getPath());
			long blockSize = stat.getBlockSize();
			long availableBlocks = stat.getAvailableBlocks();
			return availableBlocks * blockSize;
		}
		else {
			return ERROR;
		}
	}

	/**
	 * 获取SDCARD总的存储空间
	 * 
	 * @return
	 */
	public static long getTotalExternalMemorySize() {
		if (externalMemoryAvailable()) {
			File path = Environment.getExternalStorageDirectory();
			StatFs stat = new StatFs(path.getPath());
			long blockSize = stat.getBlockSize();
			long totalBlocks = stat.getBlockCount();
			return totalBlocks * blockSize;
		}
		else {
			return ERROR;
		}
	}

	//	/**
	//	 * 获取应用商城是否是第一次登录
	//	 * 
	//	 * @param context
	//	 * @return
	//	 */
	//	public static boolean isFirstLogin(Context context) {
	//		SharedPreferences sp = context.getSharedPreferences(ComParams.SP_NAME_MAIN, Context.MODE_PRIVATE);		
	//		return sp.getBoolean(ComParams.SP_IS_FIRST_LOGIN, true);
	//	}
	//	
	//	/**
	//	 * 设置应用商城是否是第一次登录标示位
	//	 * 
	//	 * @param context
	//	 * @return
	//	 */
	//	public static boolean setFirstLogin(Context context, boolean isFirstLogin) {
	//		return context.getSharedPreferences(ComParams.SP_NAME_MAIN, Context.MODE_PRIVATE).edit()
	//				.putBoolean(ComParams.SP_IS_FIRST_LOGIN, isFirstLogin).commit();
	//	}

	/**
	 * 获取Category ID
	 * 
	 * @param context
	 * @return
	 */
	public static int getCID(Context context) {
		SharedPreferences sp = context.getSharedPreferences(ComParams.SP_NAME_MAIN, Context.MODE_PRIVATE);
		return sp.getInt(ComParams.SP_CATEGORY_ID, 1);
	}

	/**
	 * 保存Category ID
	 * 
	 * @param context
	 * @param username
	 * @return
	 */
	public static boolean saveCID(Context context, int cid) {
		LogUtil.d(TAG, "saveCID CID = " + cid);
		if (cid <= 0) {
			return false;
		}
		return context.getSharedPreferences(ComParams.SP_NAME_MAIN, Context.MODE_PRIVATE).edit().putInt(ComParams.SP_CATEGORY_ID, cid).commit();
	}

	/**
	 * 获取原来的应用商城老账户名
	 * 
	 * @param context
	 * @return
	 */
	public static String getUserName(Context context) {
		SharedPreferences sp = context.getSharedPreferences(ComParams.SP_NAME_MAIN, Context.MODE_PRIVATE);
		return sp.getString(ComParams.SP_USER_NAME, "");
	}

	/**
	 * 获取应用商城账户名
	 * 
	 * @param context
	 * @return
	 */
	public static String getOTTUserName(Context context) {
		SharedPreferences sp = context.getSharedPreferences(ComParams.SP_NAME_MAIN, Context.MODE_PRIVATE);

		String username = sp.getString(ComParams.SP_OTT_USER_NAME, "");
//		if (TextUtils.isEmpty(username)) {
//			username = "MAC" + Util.getMac();
//		}
		return username;
	}

	/**
	 * 保存应用商城账户名
	 * 
	 * @param context
	 * @param username
	 * @return
	 */
	public static boolean saveOTTUserName(Context context, String username) {
		LogUtil.d(TAG, "saveUserName username = " + username);
		return context.getSharedPreferences(ComParams.SP_NAME_MAIN, Context.MODE_PRIVATE).edit().putString(ComParams.SP_OTT_USER_NAME, username).commit();
	}

	/**
	 * 获取OTT ClientID
	 * 
	 * @param context
	 * @return
	 */
	public static String getOTTClientID(Context context) {
		SharedPreferences sp = context.getSharedPreferences(ComParams.SP_NAME_MAIN, Context.MODE_PRIVATE);
		return sp.getString(ComParams.SP_OTT_CLIENTID, "");
	}

	/**
	 * 保存OTT ClientID
	 * 
	 * @param context
	 * @param username
	 * @return
	 */
	public static boolean saveOTTClientID(Context context, String clientID) {
		return context.getSharedPreferences(ComParams.SP_NAME_MAIN, Context.MODE_PRIVATE).edit().putString(ComParams.SP_OTT_CLIENTID, clientID).commit();
	}

	/**
	 * 获取应用商城账户绑定手机号
	 * 
	 * @param context
	 * @return
	 */
	public static String getPhone(Context context) {
		SharedPreferences sp = context.getSharedPreferences(ComParams.SP_NAME_MAIN, Context.MODE_PRIVATE);
		return sp.getString(ComParams.SP_USER_PHONE, "");
	}

	/**
	 * 保存应用商城绑定的手机号
	 * 
	 * @param context
	 * @param username
	 * @return
	 */
	public static boolean savePhone(Context context, String phone) {
		LogUtil.d(TAG, "savePhone phone = " + phone);
		return context.getSharedPreferences(ComParams.SP_NAME_MAIN, Context.MODE_PRIVATE).edit().putString(ComParams.SP_USER_PHONE, phone).commit();
	}

	/**
	 * 获取应用商城账户绑定邮箱
	 * 
	 * @param context
	 * @return
	 */
	public static String getEmail(Context context) {
		SharedPreferences sp = context.getSharedPreferences(ComParams.SP_NAME_MAIN, Context.MODE_PRIVATE);
		return sp.getString(ComParams.SP_USER_EMAIL, "");
	}

	/**
	 * 保存应用商城绑定的邮箱
	 * 
	 * @param context
	 * @param username
	 * @return
	 */
	public static boolean saveEmail(Context context, String email) {
		LogUtil.d(TAG, "saveEmail email = " + email);
		return context.getSharedPreferences(ComParams.SP_NAME_MAIN, Context.MODE_PRIVATE).edit().putString(ComParams.SP_USER_EMAIL, email).commit();
	}

	/**
	 * 获取应用商城账户昵称
	 * 
	 * @param context
	 * @return
	 */
	public static String getNickName(Context context) {
		SharedPreferences sp = context.getSharedPreferences(ComParams.SP_NAME_MAIN, Context.MODE_PRIVATE);
		return sp.getString(ComParams.SP_USER_NICKNAME, "");
	}

	/**
	 * 保存应用商城的NickName
	 * 
	 * @param context
	 * @param username
	 * @return
	 */
	public static boolean saveNickName(Context context, String nickname) {
		LogUtil.d(TAG, "saveNickName nickname = " + nickname);
		return context.getSharedPreferences(ComParams.SP_NAME_MAIN, Context.MODE_PRIVATE).edit().putString(ComParams.SP_USER_NICKNAME, nickname).commit();
	}

	/**
	 * 获取应用商城账户密码
	 * 
	 * @param context
	 * @return
	 */
	public static String getUserPwd(Context context) {
		SharedPreferences sp = context.getSharedPreferences(ComParams.SP_NAME_MAIN, Context.MODE_PRIVATE);
		return sp.getString(ComParams.SP_USER_PWD, "");
	}

	/**
	 * 保存应用商城账户密码
	 * 
	 * @param context
	 * @param username
	 * @return
	 */
	public static boolean saveUserPwd(Context context, String pwd) {
		return context.getSharedPreferences(ComParams.SP_NAME_MAIN, Context.MODE_PRIVATE).edit().putString(ComParams.SP_USER_PWD, pwd).commit();
	}

	/**
	 * 获取应用商城账户密码
	 * 
	 * @param context
	 * @return
	 */
	public static String getUserPayPwd(Context context) {
		SharedPreferences sp = context.getSharedPreferences(ComParams.SP_NAME_MAIN, Context.MODE_PRIVATE);
		return sp.getString(ComParams.SP_USER_PAYPWD, "");
	}

	/**
	 * 保存应用商城账户密码
	 * 
	 * @param context
	 * @param username
	 * @return
	 */
	public static boolean saveUserPayPwd(Context context, String pwd) {
		return context.getSharedPreferences(ComParams.SP_NAME_MAIN, Context.MODE_PRIVATE).edit().putString(ComParams.SP_USER_PAYPWD, pwd).commit();
	}

	/**
	 * 获取开发者账户
	 * 
	 * @param context
	 * @return
	 */
	public static String getDevelopAccount(Context context) {
		SharedPreferences sp = context.getSharedPreferences(ComParams.SP_NAME_MAIN, Context.MODE_PRIVATE);
		return sp.getString(ComParams.SP_DEVELOP_ACCOUNT, "");
	}

	/**
	 * 保存开发者账户
	 * 
	 * @param context
	 * @param username
	 * @return
	 */
	public static boolean saveDevelopAccount(Context context, String pwd) {
		return context.getSharedPreferences(ComParams.SP_NAME_MAIN, Context.MODE_PRIVATE).edit().putString(ComParams.SP_DEVELOP_ACCOUNT, pwd).commit();
	}

	/**
	 * 获取开发者测试密码
	 * 
	 * @param context
	 * @return
	 */
	public static String getDevelopDebugPwd(Context context) {
		SharedPreferences sp = context.getSharedPreferences(ComParams.SP_NAME_MAIN, Context.MODE_PRIVATE);
		return sp.getString(ComParams.SP_DEVELOP_DEBUG_PWD, "");
	}

	/**
	 * 保存开发者测试密码
	 * 
	 * @param context
	 * @param username
	 * @return
	 */
	public static boolean saveDevelopDebugPwd(Context context, String pwd) {
		return context.getSharedPreferences(ComParams.SP_NAME_MAIN, Context.MODE_PRIVATE).edit().putString(ComParams.SP_DEVELOP_DEBUG_PWD, pwd).commit();
	}

	/**
	 * 判断软件是否自动登陆
	 * 
	 * @param context
	 * @return
	 */
	public static Boolean isAutoLogin(Context context) {
		SharedPreferences sp = context.getSharedPreferences(ComParams.SP_NAME_MAIN, Context.MODE_PRIVATE);
		return sp.getBoolean(ComParams.SP_IS_AUTOLOGIN, false);
	}

	/**
	 * 保存应用商城是否自动登陆
	 * 
	 * @param context
	 * @param username
	 * @return
	 */
	public static boolean setAutoLogin(Context context, Boolean isChecked) {
		return context.getSharedPreferences(ComParams.SP_NAME_MAIN, Context.MODE_PRIVATE).edit().putBoolean(ComParams.SP_IS_AUTOLOGIN, isChecked).commit();
	}

	/**
	 * 返回屏幕宽度
	 * 
	 * @param context
	 * @return
	 */
	public static int getWindowWidth(Context context) {
		SharedPreferences sp = context.getSharedPreferences(ComParams.SP_NAME_WINDOW, 0);
		int width = 0;
		if (sp.contains(ComParams.SP_WINDOW_WIDTH)) {
			width = sp.getInt(ComParams.SP_WINDOW_WIDTH, 0);
		}
		if (width <= 0) {
			DisplayMetrics dm = new android.util.DisplayMetrics();
			((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(dm);
			width = dm.widthPixels;

			Editor editor = sp.edit();
			editor.putInt(ComParams.SP_WINDOW_WIDTH, width);
			editor.commit();
		}
		return width;
	}

	/**
	 * 返回屏幕高度
	 * 
	 * @param context
	 * @return
	 */
	public static int getWindowHeight(Context context) {
		SharedPreferences sp = context.getSharedPreferences(ComParams.SP_NAME_WINDOW, 0);
		int height = 0;
		if (sp.contains(ComParams.SP_WINDOW_HEIGHT)) {
			height = sp.getInt(ComParams.SP_WINDOW_HEIGHT, 0);
		}
		if (height <= 0) {
			DisplayMetrics dm = new android.util.DisplayMetrics();
			((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(dm);
			height = dm.heightPixels;

			Editor editor = sp.edit();
			editor.putInt(ComParams.SP_WINDOW_HEIGHT, height);
			editor.commit();
		}
		return height;
	}

	/**
	 * 返回屏幕密度
	 * 
	 * @param context
	 * @return
	 */
	public static float getWindowDensity(Context context) {
		SharedPreferences sp = context.getSharedPreferences(ComParams.SP_NAME_WINDOW, 0);
		float density = 0;
		if (sp.contains(ComParams.SP_WINDOW_DENSITY)) {
			density = sp.getFloat(ComParams.SP_WINDOW_DENSITY, 0);
		}
		if (density <= 0) {
			DisplayMetrics dm = new android.util.DisplayMetrics();
			((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(dm);
			density = dm.density;

			Editor editor = sp.edit();
			editor.putFloat(ComParams.SP_WINDOW_DENSITY, density);
			editor.commit();
		}
		return density;
	}

	/** 终端名称 */
	public static String getTerminalName() {
		return Build.MODEL;
	}

	/** 终端android 版本 */
	public static String getTerminalVersion() {
		return "Android " + Build.VERSION.RELEASE;
	}

	/** 客户端版本 */
	public static String getAPKVersion(Context context) {
		PackageManager localPackageManager;
		try {
			localPackageManager = context.getPackageManager();
			String str1 = context.getPackageName();
			String str2 = localPackageManager.getPackageInfo(str1, 0).versionName;
			return str2;
		} catch (PackageManager.NameNotFoundException localNameNotFoundException) {
			localNameNotFoundException.printStackTrace();
		}
		return null;
	}

	/**
	 * 客户端语种
	 * 
	 * @param context
	 * @return 1: 简体中文 ;2: 繁体中文; 3: 英文
	 */
	public static String getLanguage(Context context) {
		Locale locale = context.getResources().getConfiguration().locale;
		String language = locale.getLanguage(); // 获得语言码
		if (language.equalsIgnoreCase("zh")) {
			if (locale.getCountry().equalsIgnoreCase("TW"))
				return "2";
			return "1";
		}
		else if (language.equalsIgnoreCase("en")) {
			return "3";
		}
		else {
			return "1";
		}

	}

	/**
	 * 获取 IMSI id
	 * <p>
	 * Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE
	 * READ_PHONE_STATE}
	 * 
	 * @param context
	 * @return Returns the unique subscriber ID, for example, the IMSI for a GSM
	 *         phone. Return null if it is unavailable.
	 * */
	public static String getIMSI(Context context) {
		String imsi = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getSubscriberId();
		return TextUtils.isEmpty(imsi) ? "" : imsi;
	}

	/**
	 * 获取终端号
	 * 
	 * Returns the unique device ID, for example, the IMEI for GSM and the MEID
	 * for CDMA phones. Return null if device ID is not available.
	 * 
	 * <p>
	 * Requires Permission: {@link android.Manifest.permission#READ_PHONE_STATE
	 * READ_PHONE_STATE}
	 */
	public static String getIMEI(Context context) {
		String imei = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
		return TextUtils.isEmpty(imei) ? "NULL" : imei;
	}

	/**
	 * get device mac address
	 * 
	 * @param context
	 * @return
	 */
	public static String getExternalIPAddr(Context context) {
		SharedPreferences sp = context.getSharedPreferences(ComParams.SP_NAME_WINDOW, 0);
		String IP = "";
		if (sp.contains(ComParams.SP_IP_ADDRESS)) {
			IP = sp.getString(ComParams.SP_IP_ADDRESS, "");
		}
		if (TextUtils.isEmpty(IP)) {
			IP = getExternalIpAddr();
			Editor editor = sp.edit();
			editor.putString(ComParams.SP_IP_ADDRESS, IP);
			editor.commit();
		}
		return IP;
	}

	public static boolean saveIP(Context context, String ip) {
		return context.getSharedPreferences(ComParams.SP_NAME_WINDOW, 0).edit().putString(ComParams.SP_IP_ADDRESS, ip).commit();
	}

	/**
	 * Get the external Ip address of the devices.
	 * 
	 * @return
	 */
	public static String getExternalIpAddr() {
		String ipAddr = "";
		// Process pro;
		// try {
		// pro = Runtime.getRuntime().exec("curl ifconfig.me");
		// BufferedReader buf = new BufferedReader(new
		// InputStreamReader(pro.getInputStream()));
		// if (!TextUtils.isEmpty(ipAddr = buf.readLine())) {
		// LogUtil.d(TAG, "curl ifconfig.me --> " + ipAddr);
		// return ipAddr;
		// }
		// pro.destroy();
		// } catch (IOException e) {
		// e.printStackTrace();
		// }

		if (TextUtils.isEmpty(ipAddr)) {
			HttpURLConnection http = null;
			try {
				// 27.120.101.66
				URL url = new URL("http://ifconfig.me/ip");
				http = (HttpURLConnection) url.openConnection();
				http.setRequestMethod("GET");
				BufferedReader buf = new BufferedReader(new InputStreamReader(http.getInputStream()));
				while (!TextUtils.isEmpty(ipAddr = buf.readLine())) {
					LogUtil.d(TAG, " IP --> " + ipAddr);
					return ipAddr;
				}
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				if (http != null)
					http.disconnect();
			}

		}
		return ipAddr;
	}

	/**
	 * Get Local Device Mac Address
	 * 
	 * @param context
	 * @return
	 */
	public static String getLocalMacAddress(Context context) {
		WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
		WifiInfo info = wifi.getConnectionInfo();
		return info.getMacAddress();
	}

	/**
	 * 获取当前使用的网卡Mac prop.AccessType : Wlan：无线连接 Cable：有线连接
	 * 
	 * 先去Eth的Mac,取不到的话再取Wlan的Mac
	 * 
	 * @return
	 */
	public static String getMac() {
		//		String access = SystemProperties.get("prop.AccessType", "-1");
		//		LogUtil.d(TAG, "getMac prop.AccessType = " + access);
		//		if (access.contains("Wlan")) {
		//			return getWlanMacAddr();
		//		}
		//		else {
		String ethMac = getEthMacAddr();
		if (TextUtils.isEmpty(ethMac) || ethMac.equalsIgnoreCase("null")) {
			return getWlanMacAddr();
		}
		return ethMac;
		//		}

	}

	/**
	 * 获取无线网卡的Mac
	 * 
	 * @return
	 */
	public static String getWlanMacAddr() {
		try {
			for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
				NetworkInterface intf = en.nextElement();
				if (intf.getName().indexOf("wlan") >= 0) {
					return Hex.encodeHexStr(intf.getHardwareAddress(), false);
				}
			}
		} catch (Exception ex) {
			Log.e(TAG, "getWlanMacAddr Exception" + ex.toString());
		}
		return "";
	}

	/**
	 * 获取有线网卡的Mac
	 * 
	 * @return
	 */
	public static String getEthMacAddr() {
		try {
			for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
				NetworkInterface intf = en.nextElement();
				if (intf.getName().indexOf("eth") >= 0) {
					return Hex.encodeHexStr(intf.getHardwareAddress(), false);
				}
			}
		} catch (Exception ex) {
			Log.e(TAG, "getEthMacAddr Exception" + ex.toString());
		}
		return "";
		//		return "5CC6D0C90214";//"AC4AFE39FA0F";//"5CC6D0C90214";
	}

	public static byte[] getEthMacAddress() {
		byte[] eth = null;
		try {
			for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
				NetworkInterface intf = en.nextElement();
				LogUtil.v(TAG, "NetworkInterface Name = " + intf.getName());
				if (null != intf.getHardwareAddress())
					LogUtil.v(TAG, "NetworkInterface Mac = " + Hex.encodeHexStr(intf.getHardwareAddress()));
				if (intf.getName().indexOf("eth") >= 0) {
					// return intf.getHardwareAddress();
					eth = intf.getHardwareAddress();

				}
			}
		} catch (SocketException ex) {
			LogUtil.e(TAG, "WifiPreference IpAddress" + ex.toString());
		}
		return eth;
	}

	/**
	 * get device mac address
	 * 
	 * @param context
	 * @return
	 */
	public static String getMacAddr(Context context) {
		SharedPreferences sp = context.getSharedPreferences(ComParams.SP_NAME_WINDOW, 0);
		String Mac = "";
		if (sp.contains(ComParams.SP_MAC_ADDRESS)) {
			Mac = sp.getString(ComParams.SP_MAC_ADDRESS, "");
		}
		if (TextUtils.isEmpty(Mac)) {
			Mac = getMacAddress();
			Editor editor = sp.edit();
			editor.putString(ComParams.SP_MAC_ADDRESS, Mac);
			editor.commit();
		}
		return Mac;
	}

	public static String getMacAddress() {
		String result = "";
		String Mac = "";
		result = callCmd("busybox ifconfig", "HWaddr");

		if (result == null) {
			return "网络出错，请检查网络";
		}

		// 例如：eth0 Link encap:Ethernet HWaddr 00:16:E8:3E:DF:67
		if (result.length() > 0 && result.contains("HWaddr") == true) {
			Mac = result.substring(result.indexOf("HWaddr") + 6, result.length() - 1);
			Mac = Mac.replaceAll(" ", "");
			LogUtil.i(TAG, "Mac:" + Mac + " Mac.length: " + Mac.length());
		}
		return Mac;
	}

	public static String callCmd(String cmd, String filter) {
		String result = "";
		String line = "";
		try {
			// Process proc = Runtime.getRuntime().exec("su");
			// proc.getOutputStream().write(cmd.getBytes());
			// proc.getOutputStream().flush();

			Process proc = Runtime.getRuntime().exec("/system/bin/sh -");
			DataOutputStream os = new DataOutputStream(proc.getOutputStream());
			os.writeBytes(cmd + "\n");

			InputStreamReader is = new InputStreamReader(proc.getInputStream());
			BufferedReader br = new BufferedReader(is);
			while ((line = br.readLine()) != null && line.contains(filter) == false) {
				result += line;
				LogUtil.i(TAG, "line: " + line);
			}

			result = line;
			LogUtil.i(TAG, "result: " + result);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public static String getApkPath(String pkgName) {
		String line = "";
		Process proc = null;
		DataOutputStream os = null;
		InputStreamReader is = null;
		try {
			String cmd = "pm path " + pkgName;

			proc = Runtime.getRuntime().exec("/system/bin/sh -");
			os = new DataOutputStream(proc.getOutputStream());
			os.writeBytes(cmd + "\n");

			is = new InputStreamReader(proc.getInputStream());
			BufferedReader br = new BufferedReader(is);
			if ((line = br.readLine()) != null) {
				LogUtil.d(TAG, "getApkPath: " + line);
			}

			if (os != null)
				os.close();
			if (is != null)
				is.close();
			if (br != null)
				br.close();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (proc != null)
				proc.destroy();

		}
		return line;
	}

	/**
	 * check a file is exist or not
	 * 
	 * @param args
	 *            commond array
	 * @return boolean file is exist return true, others return false
	 */
	public static boolean checkFileIsExistOrNot(String... args) {
		boolean rslt = false;

		if (args != null && args.length > 0) {
			String findRslt = shellCommAndReturn(args);
			LogUtil.d(TAG, "checkFileIsExistOrNot-->findRslt:" + findRslt + " ; of cmmd:" + Arrays.toString(args));
			//file is not exist
			if (findRslt != null && findRslt.trim().contains("/system/app/"))
				rslt = true;
		}

		return rslt;
	}

	private static String			rslt				= null;
	private static boolean			excuteDone			= false;
	private static ProcessBuilder	processBuilder		= null;
	private static Process			process				= null;
	private final static int		DEFAULT_EXCUTE_TIME	= 10;		//second

	public static synchronized String shellCommAndReturn(final String... args) {

		rslt = null;
		excuteDone = false;
		//works Too
		//String[] args = { "/system/bin/pm", "install","-r",apkFilePath};
		if (args == null || args.length < 1) {
			return rslt;
		}

		if (processBuilder == null) {
			processBuilder = new ProcessBuilder(args);
			processBuilder.redirectErrorStream(true);
		}

		Thread excutThread = new Thread(new Runnable() {

			@Override
			public void run() {

				InputStream inIs = null;
				try {
					List<String> commands = new ArrayList<String>();
					commands.add("/system/bin/sh");
					commands.add("-c");
					// commands.add("busybox ifconfig eth0 | grep bytes | awk '{print $6}' | awk -F : '{print $2}'");

					StringBuffer command = new StringBuffer();
					for (String string : args) {
						command.append(string + " ");
					}
					commands.add(command.toString().trim());

					processBuilder.command(commands);
					// processBuilder.command(args);

					ByteArrayOutputStream baos = new ByteArrayOutputStream();
					int read = -1;
					process = processBuilder.start();

					inIs = process.getInputStream();
					while ((read = inIs.read()) != -1) {
						baos.write(read);
					}
					baos.flush();
					byte[] data = baos.toByteArray();
					rslt = new String(data);
					excuteDone = true;
				} catch (IOException e) {
					e.printStackTrace();
				} catch (Exception e) {
					e.printStackTrace();
				} finally {
					try {
						if (inIs != null) {
							inIs.close();
						}
					} catch (IOException e) {
						e.printStackTrace();
					}
					if (process != null) {
						process.destroy();
					}
				}
			}
		});
		excutThread.start();

		for (int i = 0; i < DEFAULT_EXCUTE_TIME * 2; i++) {
			try {
				Thread.sleep(500);
				LogUtil.d(TAG, "shellCommAndReturn index " + i + ":" + Arrays.toString(args));
				if (excuteDone) {
					LogUtil.d(TAG, "shellCommAndReturn excute done rslt is :" + rslt + " , " + Arrays.toString(args));
					break;
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}

		if (process != null) {
			process.destroy();
		}

		return rslt;
	}

	/**
	 * Get Local Ip Address
	 * 
	 * @return
	 */
	public static String getLocalIpAddress() {
		try {
			for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
				NetworkInterface intf = en.nextElement();
				for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
					InetAddress inetAddress = enumIpAddr.nextElement();
					if (!inetAddress.isLoopbackAddress()) {
						return inetAddress.getHostAddress().toString();
					}
				}
			}
		} catch (SocketException ex) {
			LogUtil.e("WifiPreference IpAddress", ex.toString());
		}
		return null;
	}

	/**
	 * 获取当前日期，格式为yyyy年MM月dd日 HH:mm
	 * 
	 * @return
	 */
	public static String getDefDate() {
		Date dt = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日  HH：mm");
		// 最后的aa表示“上午”或“下午” HH表示24小时制 如果换成hh表示12小时制
		// SimpleDateFormat sdf = new
		// SimpleDateFormat("yyyy-MM-dd HH:mm:ss aa");
		return sdf.format(dt);
	}

	public static String getTimeStamp() {
		return new SimpleDateFormat("yyyyMMddHHmmss").format(System.currentTimeMillis());
	}

	public static Date CurrentDate() {
		return new Date(System.currentTimeMillis());
	}

	public static String size(long size) {
		if (size / (1024 * 1024) > 0) {
			float tmpSize = (float) (size) / (float) (1024 * 1024);
			DecimalFormat df = new DecimalFormat("#.##");
			return "" + df.format(tmpSize) + "MB";
		}
		else if (size / 1024 > 0) {
			return "" + (size / (1024)) + "KB";
		}
		else
			return "" + size + "B";
	}
	
	public static String convertFileSize(long size) {
        long kb = 1024;
        long mb = kb * 1024;
        long gb = mb * 1024;
 
        if (size >= gb) {
            return String.format("%.1f GB", (float) size / gb);
        } else if (size >= mb) {
            float f = (float) size / mb;
            return String.format(f > 100 ? "%.0f MB" : "%.1f MB", f);
        } else if (size >= kb) {
            float f = (float) size / kb;
            return String.format(f > 100 ? "%.0f KB" : "%.1f KB", f);
        } else
            return String.format("%d B", size);
    }

	/**
	 * 返回一个有逗号(,)隔开的字符串
	 * 
	 * @param array
	 * @return the {@code String} representation of {@code array}.
	 */
	public static String toString(String[] array) {
		if (array == null) {
			return "null"; //$NON-NLS-1$
		}
		if (array.length == 0) {
			return ""; //$NON-NLS-1$
		}
		StringBuilder sb = new StringBuilder(array.length * 5);
		sb.append(array[0]);
		for (int i = 1; i < array.length; i++) {
			sb.append(","); //$NON-NLS-1$
			sb.append(array[i]);
		}
		return sb.toString();
	}

	public static String toString(List<String> list) {
		if (list == null) {
			return "null"; //$NON-NLS-1$
		}
		int length = list.size();
		if (length == 0) {
			return ""; //$NON-NLS-1$
		}
		StringBuilder sb = new StringBuilder(length * 5);
		sb.append(list.get(0));
		for (int i = 1; i < length; i++) {
			sb.append(","); //$NON-NLS-1$
			sb.append(list.get(i));
		}
		return sb.toString();
	}

	public static byte[] readInputStream(InputStream inStream) throws Exception {
		ByteArrayOutputStream outStream = new ByteArrayOutputStream();
		byte[] buffer = new byte[1024];
		int len = 0;
		while ((len = inStream.read(buffer)) != -1) {
			outStream.write(buffer, 0, len);
		}
		inStream.close();
		return outStream.toByteArray();
	}

	/**
	 * Get the date
	 * 
	 * @param distance
	 *            The number of days from today, Positive value represents the
	 *            days after today, Negative value represents the days before
	 *            today, Zero represents today.
	 * @return
	 */
	public static String getDate(int distance, boolean stripe) {
		String date = "";
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.DATE, distance);
		String year = String.valueOf(calendar.get(Calendar.YEAR));
		String month = String.valueOf(calendar.get(Calendar.MONTH) + 1);
		String day = String.valueOf(calendar.get(Calendar.DAY_OF_MONTH));

		if (month.length() == 1) {
			month = "0" + month;
		}

		if (day.length() == 1) {
			day = "0" + day;
		}

		if (stripe) {
			date = year + "-" + month + "-" + day;
		}
		else {
			date = year + month + day;
		}
		return date;
	}

	public static void hideInput(View v) {
		InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
		if (imm.isActive()) {
			imm.hideSoftInputFromWindow(v.getApplicationWindowToken(), 0);
		}
	}

	/**
	 * 范围为0~99999999,返回结果使用ASCII 形式的十六进制编码表示
	 * 
	 * @return
	 */
	public static String getHexRandom() {
		return Integer.toHexString((int) (Math.random() * 99999999));
	}

	/**
	 * Show Alert Dialog
	 * 
	 * @param activity
	 * @param title
	 * @param message
	 */
	public static void showAlertDialog(Context context, String title, String message) {

		AlertDialog.Builder builder = new AlertDialog.Builder(context);
		builder.setTitle(title);
		builder.setMessage(message);
		builder.setPositiveButton(context.getString(R.string.ok), new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {}
		});
		AlertDialog ad = builder.create();
		ad.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
		ad.setCanceledOnTouchOutside(false);
		ad.show();
	}

	public static String getTestDataFromAssets(Context context, String filename) {
		String data = "";
		try {
			AssetManager am = context.getAssets();
			InputStream is = am.open(filename);
			if (is != null) {
				byte[] info = readInputStream(is);
				data = new String(info);
				is.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return data;
	}

	/**
	 * MD5加密字符串
	 * 
	 * @param str
	 * @return
	 * @throws ITVException
	 */
	//	public static String EncoderByMd5(String str) throws ITVException {
	//		char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
	//		try {
	//			byte[] btInput = str.getBytes();
	//			// 获得MD5摘要算法的 MessageDigest 对象
	//			MessageDigest mdInst = MessageDigest.getInstance("MD5");
	//			// 使用指定的字节更新摘要
	//			mdInst.update(btInput);
	//			// 获得密文
	//			byte[] md = mdInst.digest();
	//			// 把密文转换成十六进制的字符串形式
	//			int j = md.length;
	//			char str_char[] = new char[j * 2];
	//			int k = 0;
	//			for (int i = 0; i < j; i++) {
	//				byte byte0 = md[i];
	//				//将没个数(int)b进行双字节加密
	//				str_char[k++] = hexDigits[byte0 >>> 4 & 0xf];
	//				str_char[k++] = hexDigits[byte0 & 0xf];
	//			}
	//			return new String(str_char);
	//		} catch (Exception e) {
	//			throw new ITVException(e.toString(), ITVException.UTIL_ENCODERBYMD5_EXCEPTION);
	//		}
	//
	//	}

	public static String MD5Encode(String source) throws ITVException {
		if (source == null)
			return null;
		String resultString = null;
		try {
			resultString = new String(source);
			MessageDigest md = MessageDigest.getInstance("MD5");
			resultString = byte2hexString(md.digest(resultString.getBytes()));
			return resultString;
		} catch (Exception ex) {
			throw new ITVException(ex.toString(), ITVException.UTIL_ENCODERBYMD5_EXCEPTION);
		}

	}

	public static final String byte2hexString(byte[] bytes) {
		StringBuffer buf = new StringBuffer(bytes.length * 2);
		for (int i = 0; i < bytes.length; i++) {
			if (((int) bytes[i] & 0xff) < 0x10) {
				buf.append("0");
			}
			buf.append(Long.toString((int) bytes[i] & 0xff, 16));
		}
		return buf.toString();
	}

	//	/**
	//	 * 设置系统栏可见性
	//	 */
	//	public static void setSystemBarVisible(final Activity context, boolean visible) {
	//		int flag = context.getWindow().getDecorView().getSystemUiVisibility();
	//		// int fullScreen = View.SYSTEM_UI_FLAG_SHOW_FULLSCREEN;
	//		int fullScreen = 0x8;
	//		if (visible) {
	//			if ((flag & fullScreen) != 0) {
	//				context.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
	//			}
	//		}
	//		else {
	//			if ((flag & fullScreen) == 0) {
	//				context.getWindow().getDecorView().setSystemUiVisibility(flag | fullScreen);
	//			}
	//		}
	//	}
	//
	//	/**
	//	 * 判断状态栏是否显示
	//	 */
	//	public static boolean isSystemBarVisible(final Activity context) {
	//		int flag = context.getWindow().getDecorView().getSystemUiVisibility();
	//		// return (flag & View.SYSTEM_UI_FLAG_SHOW_FULLSCREEN) != 0;
	//		return (flag & 0x8) == 0;
	//	}

	public static final String[]	country_suffix	= { "aero", "asia", "biz", "cat", "com", "coop", "edu", "eu", "gov", "info", "int", "jobs", "mil", "mobi", "museum", "name", "net", "org", "pro",
			"tel", "travel", "xxx", "ac", "ae", "af", "ag", "ai", "al", "am", "an", "ao", "aq", "ar", "as", "at", "aw", "ax", "az", "ba", "bb", "bd", "be", "bf", "bg", "bh", "bi", "bj", "bm", "bn",
			"bo", "br", "bs", "bt", "bv", "bw", "by", "bz", "ca", "cc", "cd", "cf", "cg", "ch", "ck", "cl", "cm", "cn", "co", "cr", "cs", "cu", "cv", "cx", "cy", "cz", "de", "dj", "dk", "dm", "do",
			"dz", "ec", "ee", "eg", "er", "es", "et", "eu", "fi", "fj", "fk", "fm", "fo", "fr", "ga", "gb", "gd", "ge", "gf", "gg", "gh", "gi", "gl", "gm", "gn", "gp", "gq", "gr", "gs", "gt", "gu",
			"gw", "gy", "hk", "hm", "hn", "ht", "hu", "id", "ie", "il", "in", "io", "iq", "ir", "je", "jm", "jo", "jp", "kg", "ki", "km", "kn", "kp", "kr", "kw", "ky", "kz", "la", "lb", "lc", "li",
			"lk", "lr", "ls", "lt", "lu", "lv", "ly", "ma", "mc", "md", "me", "mg", "mh", "mk", "ml", "mm", "mn", "mo", "mp", "mq", "mr", "ms", "mt", "mu", "mv", "mw", "mx", "my", "na", "nc", "ne",
			"nf", "ng", "ni", "nl", "no", "np", "nr", "nu", "nz", "om", "pa", "pe", "pf", "pg", "ph", "pk", "pl", "pm", "pn", "pr", "ps", "pt", "pw", "py", "qa", "re", "ro", "rs", "ru", "rw", "sa",
			"sb", "sc", "sd", "se", "sg", "sh", "si", "sj", "sk", "sl", "sm", "sn", "so", "sr", "st", "su", "sv", "sy", "sz", "tc", "td", "tf", "tg", "th", "tj", "tk", "tl", "tm", "tn", "to", "tp",
			"tr", "tt", "tv", "tw", "tz", "ua", "ug", "uk", "us", "uy", "uz", "va", "vc", "ve", "vg", "vi", "vn", "vu", "wf", "ws", "ye", "yt", "za", "zm", "zw" };

	/**
	 * Check whether the characters are all numbers
	 * 
	 * @param str
	 * @return
	 */
	public static boolean IsPhoneNumber(String str) {
		LogUtil.v(TAG, TAG + "  IsPhoneNumber(): " + str);
		if (Pattern.compile("^\\+?[0-9]*").matcher(str).matches())
			return true;
		else
			return false;
	}

	/**
	 * Checking whether the characters is a email
	 * 
	 * @param str
	 * @return
	 */
	public static boolean IsEmailAddr(String str) {
		LogUtil.v(TAG, TAG + "  IsEmailAddr(): " + str);
		String estr = "^[a-zA-Z0-9._-]{1,}@[a-zA-Z0-9_-]{1,}(.([a-zA-Z0-9]){2,3}){1,3}$";
		if (Pattern.compile(estr).matcher(str).matches()) {
			String[] suffix = str.substring(str.indexOf("@") + 1).split("\\.");
			LogUtil.v(TAG, "suffix.length = " + suffix.length);
			if (suffix.length <= 1) {
				return false;
			}
			for (int i = 0; i < country_suffix.length; i++) {
				if (country_suffix[i].equals(suffix[suffix.length - 1])) {
					return true;
				}
			}
			return false;
		}
		else
			return false;
	}

	/**
	 * Checking whether the characters is legal characters
	 * 
	 * @param str
	 * @return
	 */
	public static boolean IsLegalName(String str) {
		// String estr = "[a-zA-Z0-9.'-_ \u4e00-\u9fa5]{0,16}";
		String estr = "[a-zA-Z0-9]{6,20}";
		if (Pattern.compile(estr).matcher(str).matches()) {
			return true;
		}
		return false;
	}

	/**
	 * 
	 * @param list
	 *            需要添加的参数列表
	 * @param encode
	 *            true时，会的参数进行URLEncoder.encode(...)操作
	 * @return
	 */
	public static String encodeUrl(List<NameValuePair> list, boolean encode) {
		if (list == null || 0 == list.size()) {
			return "";
		}
		StringBuilder sb = new StringBuilder();
		boolean first = true;
		for (int loc = 0, lenght = list.size(); loc < lenght; loc++) {
			if (first)
				first = false;
			else
				sb.append("&");
			if (encode) {
				//数据为空时不传null
				if (TextUtils.isEmpty(list.get(loc).getValue()) || TextUtils.isEmpty(list.get(loc).getValue().trim()))
					sb.append(URLEncoder.encode(list.get(loc).getName()) + "=");
				else
					sb.append(URLEncoder.encode(list.get(loc).getName()) + "=" + URLEncoder.encode(list.get(loc).getValue().trim()));
			}
			else {
				//数据为空时不传null
				if (TextUtils.isEmpty(list.get(loc).getValue()) || TextUtils.isEmpty(list.get(loc).getValue().trim()))
					sb.append(list.get(loc).getName() + "=");
				else
					sb.append(list.get(loc).getName() + "=" + list.get(loc).getValue().trim());
			}
		}
		return sb.toString();
	}

	public static String encodeAuthUrl(List<NameValuePair> list, boolean encode) {
		if (list == null || 0 == list.size()) {
			return "";
		}
		StringBuilder sb = new StringBuilder();
		boolean first = true;
		for (int loc = 0, lenght = list.size(); loc < lenght; loc++) {
			if (first)
				first = false;
			else
				sb.append("$");
			if (encode) {
				if (TextUtils.isEmpty(list.get(loc).getValue()) || TextUtils.isEmpty(list.get(loc).getValue().trim()))
					sb.append(URLEncoder.encode(list.get(loc).getName()) + "=null");
				else
					sb.append(URLEncoder.encode(list.get(loc).getName()) + "=" + URLEncoder.encode(list.get(loc).getValue().trim().replace("+", "plus")));
			}
			else {
				if (TextUtils.isEmpty(list.get(loc).getValue()) || TextUtils.isEmpty(list.get(loc).getValue().trim()))
					sb.append(list.get(loc).getName() + "=null");
				else
					sb.append(list.get(loc).getName() + "=" + list.get(loc).getValue().trim().replace("+", "plus"));
			}
		}
		return sb.toString();
	}

	public static String spliceAuthUrl(List<String> list, boolean encode) {
		if (list == null || 0 == list.size()) {
			return "";
		}
		StringBuilder sb = new StringBuilder();
		boolean first = true;
		for (int loc = 0, lenght = list.size(); loc < lenght; loc++) {
			if (first)
				first = false;
			else
				sb.append("$");
			if (encode) {
				if (TextUtils.isEmpty(list.get(loc)) || TextUtils.isEmpty(list.get(loc).trim()) || "null".equalsIgnoreCase(list.get(loc)))
					sb.append("");
				else
					sb.append(URLEncoder.encode(list.get(loc).trim().replace("+", "plus")));
			}
			else {
				if (TextUtils.isEmpty(list.get(loc)) || TextUtils.isEmpty(list.get(loc).trim()) || "null".equalsIgnoreCase(list.get(loc)))
					sb.append("");
				else
					sb.append(list.get(loc).replace("+", "plus"));
			}
		}

		return sb.toString();
	}

	public static boolean	LogEnable	= false;
	public static String	LogPathName	= "/http.log";

	public static void WriteLog(String format, Object... args) {
		if (LogEnable) {
			String time = new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss ").format(new java.util.Date());
			String info = time + " " + String.format(format, args) + "\n";
			java.io.FileOutputStream fos = null;
			if (!android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {
				return;
			}
			try {
				String path = android.os.Environment.getExternalStorageDirectory() + LogPathName;
				java.io.File file = new java.io.File(path);
				file.getParentFile().mkdirs();
				fos = new java.io.FileOutputStream(file, true);
				fos.write(info.getBytes());
			} catch (Exception e) {
				Log.i("AKAZAM", "Failed saving log file.", e);
			} finally {
				try {
					if (fos != null)
						fos.close();
				} catch (Exception e) {}
			}
		}
	}

	public static String createTransactionID() {
		String SPID = "99999998";//ConfigUtil.IPTV_SPID;
		return SPID + createTimeStamp() + createAutoIncrementStr18();
	}

	public static String createTimeStamp() {
		SimpleDateFormat dayFormatter = new SimpleDateFormat("yyyyMMddHHmmss");
		String datetime = dayFormatter.format(new java.util.Date());
		return datetime;
	}

	public static String createAutoIncrementStr18() {
		SimpleDateFormat dayFormatter = new SimpleDateFormat("yyyyM");
		String year = dayFormatter.format(new java.util.Date());
		return year + System.currentTimeMillis();
	}

}
